clear all

********************************************************************************
********************************************************************************
**** When Can We Trust Regression Discontinuity Design Estimates from Close ****
*************** Elections? Evidence from Experimental Benchmarks ***************
********************************************************************************
********************************************************************************

* This file produces Table OA3 in Online Appendix C of De Magalhaes et al. 
* (Political Analysis).

cd "$dir"
use "$dir/data/personal_incumbency_advantage.dta", clear

********************************************************************************

est clear

eststo: rdrobust runningnextelection rv if rv!=0 & rv!=. & country=="Brazil", c(0) p(1) all vce(cluster constituency) kernel(uniform) bwselect(mserd)
scalar bw1 =  e(h_l)
scalar bw2 =  e(b_l)
estadd local N_obs = e(N_h_l) + e(N_h_r)
estadd scalar bw1
estadd scalar bw2
estadd local bandwidth "MSE"
estadd local polynomial "Linear"
eststo: rdrobust runningnextelection rv if rv!=0 & rv!=. & country=="Brazil", c(0) p(2) all vce(cluster constituency) kernel(uniform) bwselect(mserd)
scalar bw1 =  e(h_l)
scalar bw2 =  e(b_l)
estadd local N_obs = e(N_h_l) + e(N_h_r)
estadd scalar bw1
estadd scalar bw2
estadd local bandwidth "MSE"
estadd local polynomial "Quadratic"
eststo: rdrobust runningnextelection rv if rv!=0 & rv!=. & country=="Brazil", c(0) p(1) all vce(cluster constituency) kernel(uniform) bwselect(cerrd)
scalar bw1 =  e(h_l)
scalar bw2 =  e(b_l)
estadd local N_obs = e(N_h_l) + e(N_h_r)
estadd scalar bw1
estadd scalar bw2
estadd local bandwidth "CER"
estadd local polynomial "Linear"
eststo: rdrobust runningnextelection rv if rv!=0 & rv!=. & country=="Brazil", c(0) p(2) all vce(cluster constituency) kernel(uniform) bwselect(cerrd)
scalar bw1 =  e(h_l)
scalar bw2 =  e(b_l)
estadd local N_obs = e(N_h_l) + e(N_h_r)
estadd scalar bw1
estadd scalar bw2
estadd local bandwidth "CER"
estadd local polynomial "Quadratic"

esttab est* using "$dir/tables/Table_OA3.tex", booktabs ///
keep(Robust) nomtitles ///
replace  nonotes ///
ci(%9.3f) b(%9.3f) stats(N_obs h_l b_l, fmt(0 2)  layout(@) ///
labels("\textit{N}" "Main bandwidth" "Bias bandwidth")) collabels(none) ///
label nostar	eqlabels(none) ///
prehead(\begin{tabular}{l*{5}{c}} \toprule) ///
postfoot("") refcat(Robust "\textbf{Panel A:} Brazil", nolabel)

est clear

eststo: rdrobust runningnextelection rv if rv!=0 & rv!=. & country=="Colombia", c(0) p(1) all vce(cluster constituency) kernel(uniform) bwselect(mserd)
scalar bw1 =  e(h_l)
scalar bw2 =  e(b_l)
estadd local N_obs = e(N_h_l) + e(N_h_r)
estadd scalar bw1
estadd scalar bw2
estadd local bandwidth "MSE"
estadd local polynomial "Linear"
eststo: rdrobust runningnextelection rv if rv!=0 & rv!=. & country=="Colombia", c(0) p(2) all vce(cluster constituency) kernel(uniform) bwselect(mserd)
scalar bw1 =  e(h_l)
scalar bw2 =  e(b_l)
estadd local N_obs = e(N_h_l) + e(N_h_r)
estadd scalar bw1
estadd scalar bw2
estadd local bandwidth "MSE"
estadd local polynomial "Quadratic"
eststo: rdrobust runningnextelection rv if rv!=0 & rv!=. & country=="Colombia", c(0) p(1) all vce(cluster constituency) kernel(uniform) bwselect(cerrd)
scalar bw1 =  e(h_l)
scalar bw2 =  e(b_l)
estadd local N_obs = e(N_h_l) + e(N_h_r)
estadd scalar bw1
estadd scalar bw2
estadd local bandwidth "CER"
estadd local polynomial "Linear"
eststo: rdrobust runningnextelection rv if rv!=0 & rv!=. & country=="Colombia", c(0) p(2) all vce(cluster constituency) kernel(uniform) bwselect(cerrd)
scalar bw1 =  e(h_l)
scalar bw2 =  e(b_l)
estadd local N_obs = e(N_h_l) + e(N_h_r)
estadd scalar bw1
estadd scalar bw2
estadd local bandwidth "CER"
estadd local polynomial "Quadratic"

esttab est* using "$dir/tables/Table_OA3.tex", booktabs ///
keep(Robust) nomtitles nonumbers ///
append  nonotes ///
ci(%9.3f) b(%9.3f) stats(N_obs h_l b_l, fmt(0 2)  layout(@) ///
labels("\textit{N}" "Main bandwidth" "Bias bandwidth")) collabels(none) ///
label nostar	eqlabels(none) ///
prehead("") ///
postfoot("")	refcat(Robust "\textbf{Panel B:} Colombia", nolabel)

est clear

eststo: rdrobust runningnextelection rv if rv!=0 & rv!=. & country=="Denmark", c(0) p(1) all vce(cluster constituency) kernel(uniform) bwselect(mserd)
scalar bw1 =  e(h_l)
scalar bw2 =  e(b_l)
estadd local N_obs = e(N_h_l) + e(N_h_r)
estadd scalar bw1
estadd scalar bw2
estadd local bandwidth "MSE"
estadd local polynomial "Linear"
eststo: rdrobust runningnextelection rv if rv!=0 & rv!=. & country=="Denmark", c(0) p(2) all vce(cluster constituency) kernel(uniform) bwselect(mserd)
scalar bw1 =  e(h_l)
scalar bw2 =  e(b_l)
estadd local N_obs = e(N_h_l) + e(N_h_r)
estadd scalar bw1
estadd scalar bw2
estadd local bandwidth "MSE"
estadd local polynomial "Quadratic"
eststo: rdrobust runningnextelection rv if rv!=0 & rv!=. & country=="Denmark", c(0) p(1) all vce(cluster constituency) kernel(uniform) bwselect(cerrd)
scalar bw1 =  e(h_l)
scalar bw2 =  e(b_l)
estadd local N_obs = e(N_h_l) + e(N_h_r)
estadd scalar bw1
estadd scalar bw2
estadd local bandwidth "CER"
estadd local polynomial "Linear"
eststo: rdrobust runningnextelection rv if rv!=0 & rv!=. & country=="Denmark", c(0) p(2) all vce(cluster constituency) kernel(uniform) bwselect(cerrd)
scalar bw1 =  e(h_l)
scalar bw2 =  e(b_l)
estadd local N_obs = e(N_h_l) + e(N_h_r)
estadd scalar bw1
estadd scalar bw2
estadd local bandwidth "CER"
estadd local polynomial "Quadratic"

esttab est* using "$dir/tables/Table_OA3.tex", booktabs ///
keep(Robust) nomtitles nonumbers ///
append  nonotes ///
ci(%9.3f) b(%9.3f) stats(N_obs h_l b_l, fmt(0 2)  layout(@) ///
labels("\textit{N}" "Main bandwidth" "Bias bandwidth")) collabels(none) ///
label nostar	eqlabels(none) ///
prehead("") ///
postfoot("")	refcat(Robust "\textbf{Panel C:} Denmark", nolabel)

est clear

eststo: rdrobust runningnextelection rv if rv!=0 & rv!=. & country=="Finland", c(0) p(1) all vce(cluster constituency) kernel(uniform) bwselect(mserd)
scalar bw1 =  e(h_l)
scalar bw2 =  e(b_l)
estadd local N_obs = e(N_h_l) + e(N_h_r)
estadd scalar bw1
estadd scalar bw2
estadd local bandwidth "MSE"
estadd local polynomial "Linear"
eststo: rdrobust runningnextelection rv if rv!=0 & rv!=. & country=="Finland", c(0) p(2) all vce(cluster constituency) kernel(uniform) bwselect(mserd)
scalar bw1 =  e(h_l)
scalar bw2 =  e(b_l)
estadd local N_obs = e(N_h_l) + e(N_h_r)
estadd scalar bw1
estadd scalar bw2
estadd local bandwidth "MSE"
estadd local polynomial "Quadratic"
eststo: rdrobust runningnextelection rv if rv!=0 & rv!=. & country=="Finland", c(0) p(1) all vce(cluster constituency) kernel(uniform) bwselect(cerrd)
scalar bw1 =  e(h_l)
scalar bw2 =  e(b_l)
estadd local N_obs = e(N_h_l) + e(N_h_r)
estadd scalar bw1
estadd scalar bw2
estadd local bandwidth "CER"
estadd local polynomial "Linear"
eststo: rdrobust runningnextelection rv if rv!=0 & rv!=. & country=="Finland", c(0) p(2) all vce(cluster constituency) kernel(uniform) bwselect(cerrd)
scalar bw1 =  e(h_l)
scalar bw2 =  e(b_l)
estadd local N_obs = e(N_h_l) + e(N_h_r)
estadd scalar bw1
estadd scalar bw2
estadd local bandwidth "CER"
estadd local polynomial "Quadratic"

esttab est* using "$dir/tables/Table_OA3.tex", booktabs ///
keep(Robust) nomtitles nonumbers ///
append  nonotes ///
ci(%9.3f) b(%9.3f) stats(N_obs h_l b_l bandwidth polynomial, fmt(0 2)  layout(@) ///
labels("\textit{N}" "Main bandwidth" "Bias bandwidth" "Bandwidth selector" "Polynomial")) collabels(none) ///
label nostar	eqlabels(none) ///
prehead("") ///
postfoot(\bottomrule \end{tabular})	refcat(Robust "\textbf{Panel D:} Finland", nolabel)

est clear
